<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>KKJSBridge Fetch FormData</title>
<style>
    input {
        margin-top:20px;
        margin-bottom:20px;
    }
    button {
        background:#000;
        color:#fff;
        padding: 6px 12px;
        font-size: 14px;
        display:block;
        margin-bottom:5px;
        border:none;
        border-radius: 3px;
    }
</style>
</head>
<body>
    <input id="file" name="file" type="file" />
	<button onclick="sendFormData()">上传文件到七牛</button>
</body>
<script src="https://cdn.bootcss.com/eruda/1.5.2/eruda.min.js"></script>
<script>eruda.init();</script>
<script type="text/javascript">
    // 在 TS 目录下， npm install && npm run qtoken 可以生成 token
    function sendFormData() {
        var file = document.getElementById('file').files[0];

        var formData = new FormData();
        formData.append('key', 'bbbb-' + (new Date()).getTime());
        formData.append('token', 'RSxpQIxNIS2vo0vuQR3HX701ddS9fdlUnQ5jV8u1:KLNftMf4SpVnLT70Q0aWV0O9kDE=:eyJzY29wZSI6Imthcm9zcGljcyIsImRlYWRsaW5lIjoyMjIzMTgzMDA3fQ==');
        formData.append('file', file);

        fetch('http://upload.qiniup.com/', {
            method: 'POST',
            body: formData
        }).then(res => {
            res.text().then(function(text) {
                console.log(text);
            });
        }).catch(error => {
            console.error('Error:', error)
        });
    }
</script>
</html>
